<?php
namespace Home\Controller;
use Think\Controller;
/**
* 和金钱有关控制器，充值，体现等等
*/
class MoneyController extends Controller{
	public function withdraw(){
		$this->display();
	}
	public function purse(){
		$this->display();
	}

	public function moneyLog($type,$money,$user_id,$content=""){
		// 101:提现 ,102:消费  103充值  ,104收到红包,105红包退回,
		if ($type == '101' || $type == '102') //减钱
		{
			$user_money = M('user')->where(array('id'=>$user_id))->find('money');

			if ($user_money['money'] < $money) 
			{
				return 110; //余额不够
			}

			$result = M('user')->where(array('id'=>$user_id))->setDec('money',$money);

			$list = array(
				'add_time' =>time(),
				'money'    =>'-'.$money,
				'type'     =>'jian',
				'user_id'  =>$user_id,
				'content'  =>$content,
				'pay_type' =>'0',
				);

			$data = M('money_log')->add($list);

		}else{ // 加钱

			$result = M('user')->where(array('id'=>$user_id))->setInc('money',$money);

			$list = array(
				'add_time' =>time(),
				'money'    =>$money,
				'type'     =>$type,
				'user_id'  =>$user_id,
				'content'  =>$content,
				'pay_type' =>'0',
				);

			$data = M('money_log')->add($list);

		}

		if ($data) 
		{
			return true;
		}else
		{
			return false;
		}
	}

	public function getMoney($user_id){
		$result = M('user')->where(array('id'=>$user_id))->getField('money');

		if ($result) 
		{
			return $result;
		}else
		{
			return false;
		}
	}


}